package com.example.demo.controller;

import com.example.demo.dto.user.UserDto;
import com.example.demo.entity.User;
import com.example.demo.service.IUserService;
import com.example.demo.utils.result.Result;
import com.example.demo.utils.result.ResultUtils;
import com.example.demo.vo.user.UserVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    IUserService userService;

    @PostMapping("selectOne")
    public Result<UserVo> selectOne(@RequestBody UserDto userDto){
        User user = userService.selectOne(userDto.getName()).orElse(new User());
        UserVo userVo = new UserVo();
        BeanUtils.copyProperties(user, userVo);
        return ResultUtils.success(userVo);
    }
}
